package model

import (
	"github.com/jinzhu/gorm"
	"go-member/db"
)

// Auth
// @Description: 查询结构体
type Auth struct {
	Id         uint
	Username   string
	Account    string
	Password   string
	Created_at string
	Updated_at string
}
type ReturnAuth struct {
	Info  interface{}
	Token string
}

func (Auth) TableName() string {
	return "auth"
}

// GetAuthById
// @Description: 通过id获取管理员
// @param id
// @return any
func GetAuthById(id any) (Auth, bool) {
	mysql := db.InitMysql()
	auth := Auth{}

	e := mysql.Where("id= ?", id).Debug().First(&auth).Error
	if e == gorm.ErrRecordNotFound {
		return auth, false
	}
	return auth, true
}

// CheckAuth
// @Description: 根据账号密码判断用户是否存在
// @param account
// @param password
// @return Auth
// @return bool
func CheckAuth(account, password any) (Auth, bool) {
	mysql := db.InitMysql()
	auth := Auth{}
	e := mysql.Where("account = ?", account).Where("`password` = ?", password).Debug().First(&auth).Error
	if e == gorm.ErrRecordNotFound {
		return auth, false
	}
	return auth, true
}
